
/**
 * 
 * @description Create a new Sonettic-Cinema embed object. 
 * 				This object for dynamically choice between swfobject and 
 * 				pure html code for generation adobe flash object code
 * @constructor
 * @class
 * @version 0.1a
 */ 
function SntEmbed(id, movie, flashvars, params, attributes){
	// object fields
	this.callback = null;
	this.callbackArgs = [];
	this.movie = movie;
	this.haveSwfobject = swfobject != null ? true : false;

	this.width = 470;
	this.height = 264;

	this.id = id;
	this.flashvars = flashvars != null ? flashvars : {};
	
	// list of default object and embed attributes
	this.attributes = {
		'id' : id,
		'name' : id
	};
	
	
	
	// list of default flash object parameters
	this.params = {
	    'allowFullScreen' : 'true', 
	    'allowScriptAccess' : 'sameDomain',  
	    'bgcolor' : 'transparent',
	    'wmode' : 'transparent'	
	};
	
	// merge params and arguments if it's available in agruments
	if(params != null){
		for(var i in params){ this.params[i] = params[i]; }
	}
	
	if(attributes != null){
		for(var i in attributes){ this.attributes[i] = attributes[i]; }
	}
	return this;
};


SntEmbed.prototype = {
	/**
	 * @function
	 * @description render all embed data to flash object
	 * @param SntEmbedEngine object
	 * @return boolean
	 */
	render : function(engine){
		engine.setCallback(this.callback);
		return engine.render(this.id, 
							this.movie,
							{ width : this.width, height: this.height },
							this.flashvars, 
							this.params, 
							this.attributes
							);
	},
	
	/** 
	 * @function
	 * @description Merge flashvars
	 * @param fv Array with new flashvars
	 */
	setFlashvars : function(fv){
		for(var i in fv){ this.flashvars[i] = fv[i]; }
	},
	
	/** 
	 * @function
	 * @description set an callback function to execute after flash object initialize
	 * @param fn callback function instance
	 * @return void
	 */
	setCallback : function(fn){
		this.callback = fn;
	},
	/**
	 * @function
	 * @description Merge attributes 
	 * @param attrs List of attributes
	 */
	setAttributes : function(attrs){
		for(var a in attrs){ this.attributes[a] = attrs[a]; }
	},
	
	/** 
	 * @function
	 * @description Merge parameters
	 * @params list of params
	 */
	setParams : function(params){
		for(var p in params){ this.params[p] = params[p]; }
	},
	 /** 
	  * @function
	  * @description set container size
	  * @param width width of the video container
	  * @param height of the video container
	  */
	setSize : function(width, height){
		this.width = width;
		this.height = height;
	}
};

